package com.wwl.net;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPDemo {
    public static void main(String[] args) {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();
            show(inetAddress);
            showLine();
            InetAddress inetAddress1 = InetAddress.getByName("www.baidu.com");
            show(inetAddress1);
            showLine();
            InetAddress[] inetAddresses = InetAddress.getAllByName("www.baidu.com");
            for(InetAddress ia:inetAddresses){
                show(ia);
            }
            showLine();
            byte[] ip = new byte[]{15, (byte) 165, 30,8};
            InetAddress inetAddress2 = InetAddress.getByAddress(ip);
            show(inetAddress2);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
    public static void show(InetAddress inetAddress){
        String name = inetAddress.getHostName();
        String address = inetAddress.getHostAddress();
        System.out.println(name);
        System.out.println(address);
        System.out.println("------------------------------------------");
    }
    public static void showLine(){
        System.out.println("==========================================");
    }
}
